package org.starti.persistence;

import org.hibernate.criterion.DetachedCriteria;
import wicket.extensions.markup.html.repeater.util.SortParam;

import java.io.Serializable;
import java.util.List;


/**
 * @author <a href="mailto:claudiu.dumitrescu@gmail.com">Claudiu Dumitrescu</a>
 */
public interface PersistenceService {
    public <T> T getInstance(Class<T> type, Serializable id);

    /**
     * Get a list with all instances of supplied Entity, ordered by supplied properties.
     *
     * @param type       Entity type.
     * @param sortParams Sorting parameters
     * @return A entities list from database
     */
    public List getAllInstances(Class type, SortParam... sortParams);

    /**
     * @return a List containing all the classes this persistence
     *         service knows about
     */
    public List getAllTypes();

    public <T> T save(T instance);

    public void remove(Object instance);

    public List getInstances(DetachedCriteria criteria);

    /**
     * @param model to attach to the current persistence session
     */
    public void reattach(Object model);

    /**
     * Does a query by example
     *
     * @param example
     * @return
     */
    public List getInstances(Object example);

}
